package com.hex.liyue.launchdatemodule.presenter;

import com.hex.liyue.commonmodule.bean.BaseBean;
import com.hex.liyue.commonmodule.manager.HttpManager;
import com.hex.liyue.commonmodule.manager.UserManager;
import com.hex.liyue.commonmodule.net.ResponseListener;
import com.hex.liyue.launchdatemodule.adapter.AdapterLaunch;
import com.hex.liyue.launchdatemodule.bean.LaunchListResultBean;

/**
 * Created by WJ on 2016/6/25.
 */
public class LaunchListPresenter {
    private ILaunchListView iLaunchListView;

    public LaunchListPresenter(ILaunchListView iLaunchListView) {
        this.iLaunchListView = iLaunchListView;
    }

    /**
     * 查询我发起的约会列表
     *
     * @param page
     * @param pagenum
     */
    public void getLaunchList(int page, int pagenum) {
        //iLaunchListView.showLod("加载中...");
        HttpManager.getInstance().launchList(UserManager.getUserId(), page, pagenum, new ResponseListener<LaunchListResultBean>() {
            @Override
            public void onSuccess(LaunchListResultBean launchListResultBean) {
                iLaunchListView.setAdapter(launchListResultBean);
                iLaunchListView.closeLod();
            }

            @Override
            public void onFailure(String responseresult) {
                iLaunchListView.closeLod();
                iLaunchListView.showT(responseresult);
            }
        });
    }

    /**
     * 删除约会
     *
     * @param appointment_id
     */
    public void cancelAppointment(final AdapterLaunch.MyHolder myHolder, final String appointment_id) {
        iLaunchListView.showLod("加载中...");
        HttpManager.getInstance().cancelAppointment(UserManager.getUserId(), appointment_id, new ResponseListener<BaseBean>() {
            @Override
            public void onSuccess(BaseBean baseBean) {
                iLaunchListView.closeLod();
                iLaunchListView.updateInfo(myHolder, appointment_id);
            }

            @Override
            public void onFailure(String responseresult) {
                iLaunchListView.closeLod();
                iLaunchListView.showT(responseresult);
            }
        });
    }
}
